//
//  BaseController.swift
//  MSwift
//
//  Created by Mac on 2017/10/29.
//  Copyright © 2017年 马龙波. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa
import SwiftTheme

class BaseController: UIViewController {

    let disposeBag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = kRGB(232, g: 239, b: 239)
        cancelKeyboard()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //tab的隐藏和显示 
    public func hideTabBar(tabBarController :UITabBarController) {
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDelay(0.5)
        for subView in tabBarController.view.subviews {
            if subView.isKind(of: UITabBar.self) {
                subView.frame = CGRect(x: 0, y: kScreenH, width: subView.frame.size.width, height: subView.frame.size.height)
            }
        }
        UIView.commitAnimations()
    }
    
    public func showTabBarController(tabBarController :UITabBarController) {
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDelay(0.5)
        for subView in tabBarController.view.subviews {
            if subView.isKind(of: UITabBar.self) {
                subView.frame = CGRect(x: 0, y: kScreenH-subView.frame.size.height, width: subView.frame.size.width, height: subView.frame.size.height)
            }
        }
        UIView.commitAnimations()
    }
    
    fileprivate func cancelKeyboard() {
        let gesture = UITapGestureRecognizer(target: self, action: #selector(viewTaped(gesture:)))
        gesture.cancelsTouchesInView = false
        view.addGestureRecognizer(gesture)
    }
    

    @objc func viewTaped(gesture: UITapGestureRecognizer) {
        self.view .endEditing(true)
    }
    
}
